package com.aegean.CommercialHotelBookSystem.room.action;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.aegean.CommercialHotelBookSystem.factory.BusinessFactory;
import com.aegean.CommercialHotelBookSystem.factory.MyTools;
import com.aegean.CommercialHotelBookSystem.model.Hotel;
import com.aegean.CommercialHotelBookSystem.room.business.IRoomBusiness;

/**
 * Servlet implementation class UpdateRoomAction
 */
public class UpdateRoomAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UpdateRoomAction() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String Hotel_Name = null;
		String Room_Name = null;
		float Room_TotalMoney;
		float Room_Discount;
		int Room_Count;
		String Room_Type = null;
		String Room_Date = null;
		int Room_Id;
		Room_Id = Integer.parseInt(request.getParameter("Room_Id"));
		Room_Name = MyTools.toGB2312(request.getParameter("Room_Name"));
		Room_TotalMoney = Float.parseFloat(request
				.getParameter("Room_TotalMoney"));
		Room_Discount = Float.parseFloat(request.getParameter("Room_Discount"));
		Room_Count = Integer.parseInt(request.getParameter("Room_Count"));
		Room_Type = MyTools.toGB2312(request.getParameter("Room_Type"));
		Room_Date = request.getParameter("Room_Date");
		IRoomBusiness business = BusinessFactory.createRoomBusiness();
		boolean result = business.updateRoom(Room_Id, Room_Name,
				Room_TotalMoney, Room_Discount, Room_Count, Room_Type,
				Room_Date);
		if (result == true) {
			request.getRequestDispatcher("Room_list.action").forward(
					request, response);
		} else {
			request.getRequestDispatcher("Room_update.jsp").forward(
					request, response);
		}
	}

}
